#include "netcal.hpp"
#include "protocol.hpp"
#include "tcpserver.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage : " << argv[0] << " port" << std::endl;
        return -1;
    }
    uint16_t port = std::stoi(argv[1]);

    // 1. cal
    Cal cal;
    // 2. 协议
    std::unique_ptr<Protocol> pro = std::make_unique<Protocol>([&cal](Request &req) -> Responce
                                                               { return cal.Service(req); });

    // TcpServer
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&pro](std::shared_ptr<Socket> sock, InetAddr &addr)
                                                                  { pro->GetRequest(sock, addr); });
    tsvr->Start();
    return 0;
}